<%@ page import="ar.com.hakasoft.utils.NumberUtil" %>

<html>
<head>
<meta name="layout" content="mainApp" />
<g:javascript library="jquery"  /> 
<g:javascript library="facturaSinCobrar" />

</head>
<body>

    <g:if test="${flash.message}">
   		<div class="message">${flash.message}</div>
    </g:if>
    
	<div align="center" style="margin-top: 50px;">
	 	<g:uploadForm name="form" controller="facturasSinCobrar" action="cobrar" >
	 		<g:hiddenField name="idFactura" name="idFactura" value="" />
	 		<div id="items" align="center">
				<table>
			        <thead>
			            <tr>
			            	<th width="5%">ID</th>
			                <th width="15%">Fecha</th>
			                <th width="20%">Diet&eacute;tica / Vendedor</th>
			                <th width="10%">Total</th>
			                <th width="10%">Parcial</th>
			                <th width="10%"></th>
			                <th width="25%"></th>
			                <th width="5%"></th>
			            </tr>
			        </thead>
			        <tbody>
				        <g:each in="${listaFacturasSinCobrar}" status="i" var="factura">
				            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
				            	<td align="left">${factura?.id}</td>
				                <td align="left"><g:formatDate format="dd/MM/yyyy" date="${factura?.fecha}"/></td>
				                <td align="left">${factura.dietetica?:factura?.vendedor?:factura?.cliente}</td>
				                <td align="right">${NumberUtil.setearDecimales(factura.precioTotal, 2)}</td>
				                <td align="right">${NumberUtil.setearDecimales(factura.precioParcial, 2)}</td>
				                <td align="right">
				                	<button name="botonCobroTotal${factura.id}" id="botonCobroTotal${factura.id}" onclick="cobrarFactura('${factura.id}')">Cobro total</button>
								</td>
				                <td align="right">
				               		<g:hiddenField name="precioParcial${factura.id}" id="precioParcial${factura.id}" value="${factura.precioParcial}"/>
				                	<g:hiddenField name="total${factura.id}" id="total${factura.id}" value="${factura.precioTotal}"/>
				                	<g:textField name="cobroParcial${factura.id}" id="cobroParcial${factura.id}" size="8"/>
				                	<button name="botonCobroParcial${factura.id}" id="botonCobroParcial${factura.id}" onclick="cobroFacturaParcial('${factura.id}');">Cobro parcial</button>
				                </td>
				                <td><g:link controller="facturasSinCobrar" action="eliminarFactura" id="${factura.id}"><img src="${resource(dir:'images',file:'delete.png')}" alt="Eliminar" border="0" onclick="if (!confirm('Desea eliminar la factura?')){return false;}" /></g:link></td>
				            </tr>
				        </g:each>
			        </tbody>
			    </table>
			</div>
					 		
		</g:uploadForm>
		
		<div style="height: 30px;"></div>
		<div id="reporteDiv"></div>
	
	</div>

	
</body>
</html>